package com.bs.alibabauserproducer.service.impl;

import com.bs.alibabauserproducer.mapper.AccountMapper;
import com.bs.alibabauserproducer.pojo.Account;
import com.bs.alibabauserproducer.service.AccountService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author: Tvemic⁹
 * @DateTime: 2022/7/5 9:29
 * @Description: TODO
 */

@Service
public class AccountServiceImpl implements AccountService {

    @Resource
    AccountMapper accountMapper;

    @Transactional
    @Override
    public int updateAccountInfo(Account account) {
        //条件
        Example example = new Example(Account.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("accountNo", 1);
        Account ac = accountMapper.selectOneByExample(example);
        Integer amount = ac.getAccountBalance() + account.getAccountBalance();
        account.setAccountBalance(amount);
        account.setAccountNo("1");
        return accountMapper.updateByExampleSelective(account,example);
    }
}
